/**
 * Universidad del Valle de Guatemala
 * CC2003 Algoritmos y Estructuras de Datos
 * Proyecto 1: Intérprete de LISP --> Lambda LISP
 * @version 2 Septiembre, 2009
 * Integrantes:
 *      @author Julio Chicas, José García, Ernesto Rodríguez, Karen Tojín
 **/
/**
 * Description: Class with thread for managing requests from a particular client
 **/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author josegarcia
 */
public class ListThread extends Thread{
    private Socket socket=null;
    private ArrayList<Request> tasks;
    private Object lockTasks;
   
    public ListThread(Socket socket, ArrayList<Request> tasks, Object lockTasks) 
    {
    	super();
    	this.socket=socket;
    	this.tasks=tasks;
    	this.lockTasks=lockTasks;
    }
    public void run()
    {
    	try {
            //while(true){
    	   
    	    ObjectInputStream in = new ObjectInputStream((socket.getInputStream()));

    	  
    	    
    	    
    	    
    	    Object req=null;
		try {
		    req = in.readObject();
		} catch (ClassNotFoundException ex) {
		    ex.printStackTrace();
		}
    	   

            Request task=new Request(socket,req,System.currentTimeMillis());
                synchronized(tasks){
                    tasks.add(task);
                    tasks.notifyAll();
                }
            //}
            
       
    	}catch(IOException e){
    		System.out.println("Error I/O nn");
                System.out.println(e.getMessage());
		e.printStackTrace();
    	}
	//notifyAll();
    }
    

    



}
